package behavioral_pattern.mediator_pattern.concrete_colleague;

import behavioral_pattern.mediator_pattern.colleague.IDepartment;
import behavioral_pattern.mediator_pattern.mediator.IMediator;
/*
 * @Author xuhj
 * @Description 销售部门
 * @Date 12:17 下午 2022/1/9
 * @Param
 * @return
 **/
public class SaleDepartment extends IDepartment {
    public SaleDepartment(IMediator mediator) {
        super(mediator);
    }

    public void setProductNum(Integer productNum) {
        this.productNum += productNum;
    }


    /** 销售商品 */
    @Override
    public void work(Integer num) {
        if (productNum > num) {
            System.out.println("当前货架商品有 "+productNum+" 件, 销售了" + num + "件");
            this.productNum -= num;
            if (this.productNum > 20) {
                System.out.println("剩余商品"+productNum+"件, 货品充足");
            } else {
                // 补品不足, 通知补货
                System.out.println("剩余商品"+productNum+"件, 货品不足");
                communicat(COMMUNICATION_TYPE_ADD_PRODUCT);
            }
        } else {
            // 商品不足, 通知补货
            communicat(COMMUNICATION_TYPE_ADD_PRODUCT);
        }
    }

    @Override
    public void communicat(String communicationType) {
        if (communicationType.equals(COMMUNICATION_TYPE_ADD_PRODUCT)) {
            System.out.println("货品不足, 需要补货");
            mediator.operate(communicationType, 50);
        } else if (communicationType.equals(COMMUNICATION_TYPE_ADD_PRODUCT_FINISH)) {
            setProductNum(10);
            work(0);
        } else if (communicationType.equals(COMMUNICATION_TYPE_PURCHASEING)) {
            System.out.println("库存不足, 采购中....");
        }
    }
}
